import { defineAsyncComponent } from 'vue';

async function loadComponent(componentName:any) {
    console.log(await defineAsyncComponent(() =>
        import(`@/components/main/${componentName}-view.vue`)
    ))
  return defineAsyncComponent(() =>
    import(`@/components/main/${componentName}-view.vue`)
  );
}

export function generateRoutes(menuList:any) {
  const routes:any = [];
  if(menuList == undefined) return routes;
   menuList.forEach(menu => {
    const route = {
      path: menu.path,
      name: menu.name,
      meta:{
        name:menu.name,
        icon:menu.icon
      },
      component: loadComponent(menu.path.replace("/","")),
      children: menu.children ? generateRoutes(menu.children) : []
    };
    routes.push(route);
  });

  return routes;
}

